/// 发送短信验证码响应模型
class SmsResponse {
  final String status;
  final String message;
  final SmsApiResponse? apiResponse;
  final String? phone;

  SmsResponse({
    required this.status,
    required this.message,
    this.apiResponse,
    this.phone,
  });

  /// 从JSON创建实例
  factory SmsResponse.fromJson(Map<String, dynamic> json) {
    return SmsResponse(
      status: json['status'] ?? '',
      message: json['message'] ?? '',
      apiResponse: json['api_response'] != null 
          ? SmsApiResponse.fromJson(json['api_response'])
          : null,
      phone: json['phone'],
    );
  }

  /// 转换为JSON
  Map<String, dynamic> toJson() {
    return {
      'status': status,
      'message': message,
      if (apiResponse != null) 'api_response': apiResponse!.toJson(),
      if (phone != null) 'phone': phone,
    };
  }

  /// 判断是否成功
  bool get isSuccess => status == 'success';

  @override
  String toString() {
    return 'SmsResponse{status: $status, message: $message, phone: $phone, apiResponse: $apiResponse}';
  }
}

/// 短信API响应详情
class SmsApiResponse {
  final int code;
  final String msg;
  final String? smsid;

  SmsApiResponse({
    required this.code,
    required this.msg,
    this.smsid,
  });

  /// 从JSON创建实例
  factory SmsApiResponse.fromJson(Map<String, dynamic> json) {
    return SmsApiResponse(
      code: json['code'] ?? 0,
      msg: json['msg'] ?? '',
      smsid: json['smsid'],
    );
  }

  /// 转换为JSON
  Map<String, dynamic> toJson() {
    return {
      'code': code,
      'msg': msg,
      if (smsid != null) 'smsid': smsid,
    };
  }

  /// 判断短信API是否成功
  bool get isSuccess => code == 2; // 根据测试结果，code为2表示成功

  @override
  String toString() {
    return 'SmsApiResponse{code: $code, msg: $msg, smsid: $smsid}';
  }
}
